import request from '@/utils/request'

function getAllClassRoom() {
  return request({
    url: '/classroom/',
    method: 'get'
  })
}

async function getClassRoomOptions() {
  const data = await getAllClassRoom()
  const rawData = data.data
  for(let campus of rawData){
    campus.value = campus.id.toString();
    campus.label = campus.name
    for(let building of campus.buildings) {
      building.value = building.id.toString();
      building.label = building.name;
      for(let room of building.rooms) {
        room.value = room.id.toString()
        room.label = room.name
      }
      building.children = building.rooms;
    }
    campus.children = campus.buildings;
  }
  return rawData;
}

export default {
  getAllClassRoom,
  getClassRoomOptions
}
